package cn.zhagzheguo.xk.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.zhagzheguo.xk.dao.CourseDao;
import cn.zhagzheguo.xk.model.Course;

@Controller
@RequestMapping("/course")
public class CourseController {

	@Autowired
	private CourseDao courseDao;

	@RequestMapping("/one")
	@ResponseBody
	public Course getCourse(@RequestParam("courseId") int courseId) {
		Course course = courseDao.getCourse(courseId);
		System.out.println("/course/one: " + course.toString());
		return course;
	}

	@RequestMapping("/all")
	@ResponseBody
	public List<Course> getAllByPage(@RequestParam("id") int id) {
		List<Course> list = courseDao.getAllByPage(id);
		System.out.println("/course/all:id=" + id + ",list.size=" + list.size() + ",list=" + list.toString());
		return list;
	}

	@RequestMapping("/filte")
	@ResponseBody
	public List<Course> filteCourse(Course course) {
		System.out.println("/course/filte:" + course.toString());
		List<Course> list = courseDao.filteAll(course);
		return list;
	}

	// syllabus:大纲（课程大纲）
	@RequestMapping("/syllabus")
	@ResponseBody
	public String courseSyllabus(@RequestParam("course_id") int id) {
		return null;
	}

	@RequestMapping(value = "/search")
	@ResponseBody
	public List<Course> getCourseByKeyword(@RequestParam("key") String key, @RequestParam("id") int id) {
		System.out.println("key=" + key + ",id=" + id);
		List<Course> list = courseDao.getByKeyword(key, id);
		System.out.println("list.size=" + list.size() + ",list=" + list.toString());
		return list;
	}

	@RequestMapping("/find_no")
	@ResponseBody
	public Course getCourseByConAndKxh(@RequestParam("cno") String cno, @RequestParam("kxh") int kxh) {
		Course course = courseDao.getCourseByCnoAndKxh(cno, kxh);
		return course;
	}

	@RequestMapping("/find_name")
	@ResponseBody
	public List<Course> getCourseByName(@RequestParam("name") String name, @RequestParam("id") int id) {
		List<Course> list = courseDao.getByName(name, id);
		return list;
	}

	public void setCourseService(CourseDao courseService) {
		this.courseDao = courseService;
	}

}
